package cong.test.http;

import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author xiezhicong xiezc@3vjia.com
 * @since 2021-07-15 10:48
 */
public class RequestDemo {

    public static void main(String[] args) {
        sendData();
    }

    public static void sendData() {
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("POST /examples/servlets/servlet/HelloWorldExample HTTP/1.1\r\n");
            sb.append("Host: 127.0.0.1\r\n");
            sb.append("Connection: keep-alive\r\n");
            sb.append("sysCode: ihomewms\r\n");
            sb.append("Cookie: HCP=d-ceec106c6245a5bf178283e17d4782\r\n");
            sb.append("Content-Type: application/json\r\n");
            sb.append("User-Agent: PostmanRuntime/7.28.1\r\n");
            sb.append("test: 123\r\n");
            sb.append("Content-Length: 52\r\n");
            sb.append("\r\n");
            sb.append("[{\"stockOrganId\":\"GDMXBZ\",\"mmId\":98550105052921856}]");
            String data = sb.toString();
            Socket socket = new Socket();
            socket.connect(new InetSocketAddress("127.0.0.1", 8080), 4000);
            socket.getOutputStream().write(data.getBytes());
            byte[] b = new byte[5012];
            int read = socket.getInputStream().read(b);
            System.out.println(new String(b, 0, read));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


